package com.shxzz.shortlink.admin.common.serialize;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @author shxzz
 * @create 2023-12-10-15:39
 * @description 手机号脱敏序列化器
 */
public class PhoneDesensitizationSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String desensitizedPhone = DesensitizedUtil.mobilePhone(phone);

        jsonGenerator.writeString(desensitizedPhone);
    }
}
